package cn.laixueit.resource.upload.service;

import cn.laixueit.resource.upload.mapper.TbFileMapper;
import cn.laixueit.resource.upload.po.TbFile;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author duxiang
 * @date 2024/2/23 15:29
 */
@Service
public class FileService{

    @Resource
    private TbFileMapper fileMapper;

    public TbFile checkFile(String fileMd5) {
        QueryWrapper<TbFile> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(TbFile::getFileMd5,fileMd5);
        TbFile tbFile = fileMapper.selectOne(wrapper);
        return tbFile;
    }

    public TbFile uploadFile(MultipartFile partFile, String name, String fileMd5) {
        // 创建文件夹
        // 上传文件到指定文件夹
        // 保存数据tbFile
        TbFile tbFile = TbFile.builder()
                .fileMd5(fileMd5)
                .build();
        fileMapper.insert(tbFile);
        return tbFile;
    }
}
